package com.lebang.medicalInquiry.controller;
/**
 * @author: zpc
 * @date:
 * @version V1.0
 */


import com.lebang.medicalInquiry.constant.ResponseEnum;
import com.lebang.medicalInquiry.model.po.FigureVoice;
import com.lebang.medicalInquiry.model.vo.PageVo;
import com.lebang.medicalInquiry.response.Callback;
import com.lebang.medicalInquiry.response.JsonData;
import com.lebang.medicalInquiry.service.FigureVoiceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RequestMapping("/figure/theme")
@Api(tags = "人物音库")
@RestController
public class FigureVoiceController {
    @Autowired
    private FigureVoiceService figureVoiceService;


    @GetMapping("/")
    @ApiOperation("人物音库列表")
    public JsonData themeList(HttpServletRequest request, HttpServletResponse response
            , @ApiParam(name = "keyWord", value = "搜索名称") @RequestParam(value = "keyWord", required = false) String keyWord
            , @ApiParam(name = "languageId", value = "语言") @RequestParam(value = "languageId", required = false) Integer languageId
            , @ApiParam(name = "state", value = "0 下架 1 上架") @RequestParam(value = "state", required = false) Integer state
            , @ApiParam(name = "sex", value = "性别 0 女 1男") @RequestParam(value = "sex", required = false, defaultValue = "-1") Integer sex
            , @ApiParam(name = "page", value = "页码") @RequestParam(value = "page", defaultValue = "1") Integer page
            , @ApiParam(name = "limit", value = "条数") @RequestParam(value = "limit", defaultValue = "10") Integer limit

    ) {
        try {
            PageVo list = figureVoiceService.getList( keyWord,languageId, sex, state, (page - 1) * limit, limit);
            return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo(), list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Callback.fail(ResponseEnum.UNEXCEPTION.getCode(), ResponseEnum.UNEXCEPTION.getMemo());
    }

    @PostMapping("/")
    @ApiOperation("添加或修改人物音库")
    public JsonData operaFigureVoice(HttpServletRequest request, HttpServletResponse response,
                                     @RequestBody FigureVoice figureVoiceOpearVo
    ) {


        figureVoiceService.operaFigureVoice(figureVoiceOpearVo);
        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo());

    }

    @DeleteMapping("/{figureId}")
    @ApiOperation("删除人物音库")
    public JsonData rmoveFigureVoice(HttpServletRequest request, HttpServletResponse response,
                                     @ApiParam(name = "figureId", value = "特效音库id", required = true) @PathVariable Integer figureId
    ) {
        figureVoiceService.removeById(figureId);
        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo());
    }

}
